﻿using System;
using System.Collections.Generic;
using FinPlusComponents;

namespace FinPlusAnalytics
{
    public sealed class Caches : FinPlusComponent
    {
        private static Caches _instance;
        private static object _lock = new Object();
        private static Dictionary<string, Cache> _caches = new Dictionary<string, Cache>();

        //construct
        public static Caches Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_lock)
                    {
                        if (_instance == null)
                            _instance = new Caches();
                    }
                }

                return _instance;
            }
        }

        public Cache GetCache(string name)
        {
            Cache cache;
            lock (_lock)
            {
                if (!_caches.ContainsKey(name))
                    _caches[name] = cache = new Cache(name);
                else
                    cache = _caches[name];
            }
            return cache;   
        }
    }
}
